import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vitePluginImport from "vite-plugin-babel-import";
import path from "path";
function resolve(dir) {
  return path.join(__dirname, dir);
}
console.log("eqe");
console.log(path);

var baseUrl = {
  development: "./",
  beta: "./",
  release: "./",
};

export default ({ mode }) =>
  defineConfig({
    plugins: [
      vue(),
      vitePluginImport([
        {
          libraryName: "element-plus",
          libraryDirectory: "es",
          style(name) {
            return `element-plus/lib/theme-chalk/${name}.css`;
          },
        },
      ]),
    ],
    base: baseUrl[mode],
    // 是否自动在浏览器打开
    open: false,
    // 是否开启 https
    https: false,
    lintOnSave: false, //是否开启eslint
    resolve: {
      alias: {
        "~": path.resolve(__dirname, "./"),
        "@": path.resolve(__dirname, "src"),
      },
    },
    chainWebpack(config) {
      config.module.rule("svg").exclude.add(resolve("src/icons")).end();
      config.module
        .rule("icons")
        .test(/\.svg$/)
        .include.add(resolve("src/icons"))
        .end()
        .use("svg-sprite-loader")
        .loader("svg-sprite-loader")
        .options({
          symbolId: "icon-[name]",
        })
        .end();
    },
    server: {
      port: 8088,
      proxy: {
        "/api": {
          target: "http://backend-api-02.newbee.ltd/manage-api/v1",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
    // build: {},
  });
